package com.study;

import org.jsoup.Jsoup;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author chenyeqing
 * @date 2021/11/25 22:01
 */
@Service
public class VideoService {
    public void test01(String url) {
        //定义源代码
        String code;
        //获取源代码
        code = getCodeByPath(url);
        // 去除空格和换行
        Pattern aa = Pattern.compile("\\s*|\t|\r|\n");
        Matcher m = aa.matcher(code);
        code = m.replaceAll("");
        code = code.substring(code.lastIndexOf("/download?"), code.lastIndexOf("\";"));

        System.out.println("http://bx111.xyz/" + code);
        // 打开地址
        try {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://bx111.xyz/" + code);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据URL获取源代码
     */
    public String getCodeByPath(String url) {
        String code = null;
        try {
            code = Jsoup.connect(url).execute().body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return code;
    }
}
